package cn.edu.scau.cmi.chenyiqiu.SingletonClient;

import javafx.fxml.FXML;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;

public class Controller {
	public static int count=0;
	private Marshal[] marshal=new Marshal[10];
	@FXML
	private TextField info1;
	@FXML
	private TextField info2;
	@FXML
	private TextArea text1;
	@FXML
	private TextArea text2;
	//单例输入
	private int number=0;
	public void showinfo1()
	{
		text1.clear();
		String name=info1.getText();
		if(name.length()<1)
			text1.setText("请重新输入！");
		Chairman president=Chairman.getInstance(name);
		text1.appendText(president.getName()+president);
		if(number==0) {
			number++;
			text1.appendText("\n");
		text1.appendText("创建成功！ ") ;
		}
		else
		{
			text1.appendText("\n该主席已经创建了，请重新输入！");
		}
		
	}
	//多例输入
	public void showinfo2()
	{
		text2.clear();
		if(count>10||count==10)
			text2.appendText("十大元帅已经满了，不可再添加！");
		String name =info2.getText();
		for(int i=0;i<count;i++) {
			if(marshal[i].getname().equals(name)) {
				text2.appendText("该元帅已重复！");
				return;
			}
		}
		if(count>=10)
			text2.appendText("人数已满！");
			marshal[count]=new Marshal(name);
		count++;
		for(int i=0;i<count;i++) {
			text2.appendText(1+i+"、"+marshal[i].getname()+marshal[i]);
			text2.appendText("\n");
		}
		
	}
	
}
